map<State, vector<pair<Trigger, State>>> rules;
rules[State::off_hook]={
{Trigger::call_dialed, State::connecting},
{Trigger::stop_using_phone, State::on_hook}
};
rules[State::connecting]={
{Trigger::hung_up, State::off_hook},
{Trigger::call_connected, State::connected}
};
State currentState{State::off_hook}, exitState{State::on_hook};
while(true){
cout<<"The phone is currently "<<currentState<<endl;
select_trigger:
cout<<"Select a trigger:"<<'\n';
int i=0;
for(auto item: rules[currentState]){
cout<<i++<". "<<item.first<<'\n';
}
int input;
cin>>input;
if(input<0 || (input+1)>rules[currentState].size()){
cout<<"Incorrect option. Please try again."<<'\n';
goto select_trigger;
}
currentState=rules[currentState][input].second;
if(currentState==exitState) break;
}